//
//  ItemRecords.m
//
//  Created by Jeremy Whitcher on 3/12/12.
//

#import "ItemRecords.h"

@implementation ItemRecords

#pragma mark initialization

- (id)init;
{
    if (![super init])
        return nil;
    
    itemRecords = [[NSMutableArray alloc] init];
    
    return self;
}

#pragma mark operations

- (NSUInteger) getCount
{
    return [itemRecords count];
}

- (void)addRecord : (ItemRecord *)rec
{
    [itemRecords addObject:rec];
}

- (void)delRecord : (NSUInteger)index
{
    if (index < [itemRecords count])
    {
        // remove the object from the array
        [itemRecords removeObjectAtIndex:index];
    }
}

- (ItemRecord *) getRecord : (NSUInteger) index
{
    if (index < [itemRecords count])
        return [itemRecords objectAtIndex:index];
    
    return nil;
}

- (void) replaceRecord: (NSUInteger) index : (ItemRecord *) replacementRecord
{
    if (index < [itemRecords count])
        [itemRecords replaceObjectAtIndex:index withObject:replacementRecord]; 
}

//#pragma mark NSCoding Protocol
//
//-(void) encodeWithCoder: (NSCoder *) encoder
//{
//    NSMutableArray *encodedRecords = [NSMutableArray arrayWithCapacity:[itemRecords count]];
//    for(ItemRecord *rec in itemRecords)
//    {
//        NSData *encodedRec = [NSKeyedArchiver archivedDataWithRootObject : rec];
//        [encodedRecords addObject:encodedRec];
//    }
//    [encoder encodeObject:encodedRecords];
//}
//
//-(id) initWithCoder: (NSCoder *) decoder
//{    
//    self = [super init];
// 
//    NSArray *encodedRecords = [decoder decodeObject];
//    itemRecords = [NSMutableArray arrayWithCapacity:[encodedRecords count]];
//    for(NSData *encodedRecord in encodedRecords)
//    {
//        ItemRecord *decodedRecord = (ItemRecord *)[NSKeyedUnarchiver unarchiveObjectWithData:encodedRecord];
//        [itemRecords addObject:decodedRecord];
//    }
//
//    return self;
//}

@end
